package itsm.isperp.module.controller.bpm;

import itsm.isperp.module.entity.bpm.BpmProcessSetting;
import itsm.isperp.module.service.bpm.BpmProcessSettingService;
import itsm.isperp.workflow.service.BpmProcessDefinitaionService;

import javax.servlet.http.HttpServletRequest;

import org.activiti.engine.repository.ProcessDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * 流程设置控制器
 * 
 * @author lizx
 * @date 2013-6-14
 */
@Controller
@RequestMapping("bpm")
public class BpmController {

	@Autowired
	BpmProcessSettingService bpmProcessSettingService;
	@Autowired
	BpmProcessDefinitaionService bpmProcessDefinitaionService;

	@RequestMapping("wizConfigEdit")
	public ModelAndView wizConfigEdit(String id, HttpServletRequest req) {
		ModelAndView mv = new ModelAndView("bpm/wizConfigEdit");
		BpmProcessSetting model = this.bpmProcessSettingService.findOne(id);

		ProcessDefinition processDefinition = bpmProcessDefinitaionService
				.getProcessDefinitionByKey(model.getActReProcdefKey());

		if (processDefinition.getDeploymentId() != null) {
		
			mv.addObject(
					"modelId",
					this.bpmProcessDefinitaionService.getModelByDeploymentId(
							processDefinition.getDeploymentId()).getId());

		}
		mv.addObject("processSettingId", id);

		return mv;
	}
}
